jvn.JvnServerImpl Class Reference

Inheritance diagram for jvn.JvnServerImpl:

Inheritance graph
[legend]
Collaboration diagram for jvn.JvnServerImpl:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void jvnTerminate () throws jvn.JvnException
JvnObject jvnCreateObject (Serializable o) throws jvn.JvnException
void jvnRegisterObject (String jon, JvnObject jo) throws jvn.JvnException
JvnObject jvnLookupObject (String jon, Class<?extends JvnObject > type) throws jvn.JvnException
Serializable jvnLockRead (int joi) throws JvnException
Serializable jvnLockWrite (int joi) throws JvnException
void jvnInvalidateReader (int joi) throws java.rmi.RemoteException,jvn.JvnException
Serializable jvnInvalidateWriter (int joi) throws java.rmi.RemoteException,jvn.JvnException
Serializable jvnInvalidateWriterForReader (int joi) throws java.rmi.RemoteException,jvn.JvnException

Static Public Member Functions

static JvnServerImpl jvnGetServer ()

Private Member Functions

 JvnServerImpl () throws Exception

Private Attributes

HashMap< Integer, JvnObjectjvnObjectIds = null
JvnRemoteCoord jvnCoordinator = null

Static Private Attributes

static final long serialVersionUID = -1834717182805714127L
static JvnServerImpl js = null


Detailed Description

This class implements the Javanaise Server.

Definition at line 22 of file JvnServerImpl.java.


Constructor & Destructor Documentation

jvn.JvnServerImpl.JvnServerImpl (  )  throws Exception [private]

Default constructor

Definition at line 46 of file JvnServerImpl.java.

References jvn.JvnServerImpl.jvnCoordinator, and jvn.JvnServerImpl.jvnObjectIds.

Referenced by jvn.JvnServerImpl.jvnGetServer().

00046                                                  {
00047                 jvnObjectIds = new HashMap<Integer,JvnObject>();
00048                 try {
00049                         jvnCoordinator = (JvnRemoteCoord)Naming.lookup("AT_LD_jvnCoordinator");
00050                 } catch(NotBoundException e) {
00051                         System.out.println("Coordinator not found!");
00052                         jvnCoordinator = null;
00053                 }
00054         }

Here is the caller graph for this function:


Member Function Documentation

static JvnServerImpl jvn.JvnServerImpl.jvnGetServer (  )  [static]

Static method allowing an application to get a reference to the instance of the Javanaise Server (managed as a singleton, remember)

Returns:
A valid JvnServerImpl reference if server can be created AND coordinator can be located, null otherwise.

Definition at line 63 of file JvnServerImpl.java.

References jvn.JvnServerImpl.js, and jvn.JvnServerImpl.JvnServerImpl().

00063                                                    {
00064                 if (js == null) {
00065                         try {
00066                                 js = new JvnServerImpl();
00067                         } catch (Exception e) {
00068                                 System.out.println("Error creating the Javanaise Server!\n"+e);
00069                                 return null;
00070                         }
00071                 }
00072                 return js;
00073         }

Here is the call graph for this function:

void jvn.JvnServerImpl.jvnTerminate (  )  throws jvn.JvnException

Terminates the Javanaise Server.

Implements jvn.JvnLocalServer.

Definition at line 78 of file JvnServerImpl.java.

References jvn.JvnServerImpl.jvnCoordinator, and jvn.JvnRemoteCoord.jvnServerTerminated().

00078                                                            {
00079                 JvnRemoteCoord coord = null;
00080                 synchronized(this) {
00081                         if(jvnCoordinator!=null) {
00082                                 coord = jvnCoordinator;
00083                                 jvnCoordinator = null;
00084                         }
00085                 }
00086 
00087                 System.out.println("Terminating the Javanaise Server");
00088 
00089                 try {
00090                         if (coord != null) {
00091                                 coord.jvnServerTerminated(this);
00092                         }
00093                 } catch (RemoteException e) {}
00094         }

Here is the call graph for this function:

JvnObject jvn.JvnServerImpl.jvnCreateObject ( Serializable  o  )  throws jvn.JvnException

Creates a Javanaise Object. Note that once created, the object is not registered to any Javanaise Service, it doesn't even have a valid Javanaise Object ID.

See also:
JvnServerImpl#jvnRegisterObject(String, JvnObject)
Parameters:
o : Initial content (state) of the Javanaise Object.
Returns:
A dummy Javanaise Object with the given content.

Implements jvn.JvnLocalServer.

Definition at line 107 of file JvnServerImpl.java.

Referenced by irc.Irc.main(), and counter.Counter.main().

00108                                 {
00109                 return new JvnObjectImpl(o);
00110         }

Here is the caller graph for this function:

void jvn.JvnServerImpl.jvnRegisterObject ( String  jon,
JvnObject  jo 
) throws jvn.JvnException

Gets a Javanaise Object ID for the object and registers it with the Javanaise Coordinator. Once this method succeeds, the object is accessible from all clients member of that Javanaise Service. The current server will hold a cached version of that object.

Parameters:
jon : the JVN object name
jo : the JVN object

Implements jvn.JvnLocalServer.

Definition at line 121 of file JvnServerImpl.java.

References jvn.JvnServerImpl.jvnCoordinator, jvn.JvnRemoteCoord.jvnGetObjectId(), jvn.JvnServerImpl.jvnObjectIds, and jvn.JvnRemoteCoord.jvnRegisterObject().

Referenced by irc.IrcJvn2.main(), irc.Irc.main(), counter.CounterJvn2.main(), and counter.Counter.main().

00121                                                                                         {
00122                 if(jvnCoordinator == null) {
00123                         throw new JvnException("Coordinator is not present!");
00124                 } else if(jo == null || jon == null) {
00125                         throw new JvnException("The given name or JvnObject is not valid!");
00126                 } else {
00127                         try {
00128                                 int id = jvnCoordinator.jvnGetObjectId();
00129                                 jo.jvnSetObjectId(id);
00130                                 jvnCoordinator.jvnRegisterObject(jon,jo,this);
00131 
00132                                 // Only put in cache after successful registration
00133                                 jvnObjectIds.put(id,jo);
00134                         } catch (RemoteException e) {
00135                                 throw new JvnException("Network error while registering object!\n" + e);
00136                         }
00137                 }
00138         }

Here is the call graph for this function:

Here is the caller graph for this function:

JvnObject jvn.JvnServerImpl.jvnLookupObject ( String  jon,
Class<?extends JvnObject type 
) throws jvn.JvnException

Gets a reference to a Javanaise Object based on its symbolic name.

Parameters:
jon : the JVN object name
type : the class type of the desired object
Returns:
A reference to the JVN object. Before using that reference, make sure you've done a read lock or a write lock on it.

Implements jvn.JvnLocalServer.

Definition at line 149 of file JvnServerImpl.java.

References jvn.JvnServerImpl.jvnCoordinator, jvn.JvnObject.jvnGetObjectId(), jvn.JvnRemoteCoord.jvnLookupObject(), and jvn.JvnServerImpl.jvnObjectIds.

Referenced by irc.IrcJvn2.main(), irc.Irc.main(), counter.CounterJvn2.main(), and counter.Counter.main().

00149                                                                                                               {
00150                 /*if(jvnCoordinator == null) {
00151                         throw new JvnException("Coordinator is not present!");
00152                 }*/
00153                 if (jon == null) {
00154                         throw new JvnException("The given name is not valid!");
00155                 }
00156                 if (type == null) {
00157                         throw new JvnException("The given class type is not valid!");
00158                 }
00159                 else {
00160                         try {
00161                                 //System.out.println(type.getName());
00162                                 JvnObject temp = jvnCoordinator.jvnLookupObject(jon, type, this);
00163                                 //System.out.println(temp);
00164                                 if (temp != null) {
00165                                         // A Javanaise object with name <jon> exists.
00166                                         
00167                                         // String-comparison-based type checking !
00168                                         if (temp.toString().startsWith(type.getName())) {
00169 //                                      if (temp.getClass().getName().startsWith(type.getName())) {
00170                                                 try {
00171                                                         // Try typecast...
00172                                                         // This is supposed to handle JvnObject vs. JvnObjectImpl,
00173                                                         // which string-comparison-based type checking cannot do
00174                                                         // cleanly.
00175                                                         temp.getClass().asSubclass(type);
00176                                                         // The Javanaise object with name <jon> has the same type as the
00177                                                         // given type, so we assume that it is the same object.
00178                                                         jvnObjectIds.put(temp.jvnGetObjectId(), temp);
00179                                                         ((JvnObjectImpl)temp).__containedObjectLockState = JvnObjectState.STATE_NOLOCK;
00180                                                 }
00181                                                 catch (ClassCastException e) {
00182                                                         System.err.println(type.getName());
00183                                                         System.err.println(temp.toString());
00184                                                         throw new JvnException("Object with same name, but different type, previously registered (2)!");
00185                                                 }
00186                                                 
00187                                         }
00188                                         else {
00189                                                 // Rare case: there is already a Javanaise object with name <jon>,
00190                                                 // but the type of that object is different from the given type...
00191                                                 // Trying to use the previously registered object may trigger all
00192                                                 // kinds of exceptions: ClassCastException, NoSuchMethodException, etc.
00193                                                 // We'd better signaling there's a problem.
00194                                                 System.err.println(type.getName());
00195                                                 System.err.println(temp.toString());
00196                                                 throw new JvnException("Object with same name, but different type, previously registered (1)!");
00197                                         }
00198                                 }
00199                                 
00200                                 //try {
00201                                         //c = (type.class)o;
00202                                         //type.class temp = (JvnObject)o;
00203                                         //if (o instanceof c)
00204                                         //Class.forName(className)
00205                                         if(temp!=null) {
00206                                         }
00207                                         return temp;
00208                                 //}
00209                         } catch(RemoteException e) {
00210                                 throw new JvnException("Network error!\n"+e);
00211                         } catch(ClassCastException e) {
00212                                 throw new JvnException("Unexpected class type!");
00213                         }
00214                 }
00215         }

Here is the call graph for this function:

Here is the caller graph for this function:

Serializable jvn.JvnServerImpl.jvnLockRead ( int  joi  )  throws JvnException

Get a read lock on a JVN object.

Before trying to get any lock, you must get a reference to the object using the JvnServerImpl#jvnLookupObject(String) method.

Parameters:
joi : the JVN object identification
Returns:
The current JVN object state

Implements jvn.JvnLocalServer.

Definition at line 227 of file JvnServerImpl.java.

References jvn.JvnServerImpl.jvnCoordinator, jvn.JvnRemoteCoord.jvnLockRead(), and jvn.JvnServerImpl.jvnObjectIds.

00227                                                                      {
00228                 if(jvnCoordinator == null) {
00229                         throw new JvnException("Coordinator is not present!");
00230                 } else if( jvnObjectIds.containsKey(joi) ) {
00231                         try {
00232                                 return jvnCoordinator.jvnLockRead(joi,this);
00233                         } catch (RemoteException e) {
00234                                 throw new JvnException("Network error while locking object for reading!\n" + e);
00235                         }
00236                 } else {
00237                         throw new JvnException("Unknown object ID! Plase call jvnLookupObject before calling this method!");
00238                 }
00239         }

Here is the call graph for this function:

Serializable jvn.JvnServerImpl.jvnLockWrite ( int  joi  )  throws JvnException

Get a write lock on a JVN object.

Before trying to get any lock, you must get a reference to the object using the JvnServerImpl#jvnLookupObject(String) method.

Parameters:
joi : the JVN object identification
Returns:
The current JVN object state

Implements jvn.JvnLocalServer.

Definition at line 250 of file JvnServerImpl.java.

References jvn.JvnServerImpl.jvnCoordinator, jvn.JvnRemoteCoord.jvnLockWrite(), and jvn.JvnServerImpl.jvnObjectIds.

00250                                                                       {
00251                 if(jvnCoordinator == null) {
00252                         throw new JvnException("Coordinator is not present!");
00253                 } else if( jvnObjectIds.containsKey(joi) ) {
00254                         try {
00255                                 return jvnCoordinator.jvnLockWrite(joi,this);
00256                         } catch (RemoteException e) {
00257                                 throw new JvnException("Network error while locking object for reading!\n" + e);
00258                         }
00259                 } else {
00260                         throw new JvnException("Unknown object ID! Plase call jvnLookupObject before calling this method!");
00261                 }
00262         }

Here is the call graph for this function:

void jvn.JvnServerImpl.jvnInvalidateReader ( int  joi  )  throws java.rmi.RemoteException,jvn.JvnException

Invalidates the read lock held by a Javanaise Object. This method is normally called by the Javanaise Coordinator.

Parameters:
joi : the JVN object id
See also:
JvnObjectImpl.jvnInvalidateReader()

Implements jvn.JvnRemoteServer.

Definition at line 273 of file JvnServerImpl.java.

References jvn.JvnObject.jvnInvalidateReader(), and jvn.JvnServerImpl.jvnObjectIds.

00273                                                                                                   {
00274                 JvnObject jo = jvnObjectIds.get(joi);
00275 
00276                 if( jo==null ) {
00277                         throw new JvnException("Object id not found while invalidating reader!");
00278                 } else {
00279                         jo.jvnInvalidateReader();
00280                 }
00281         }

Here is the call graph for this function:

Serializable jvn.JvnServerImpl.jvnInvalidateWriter ( int  joi  )  throws java.rmi.RemoteException,jvn.JvnException

Invalidates the write lock held by a Javanaise Object. This method is normally called by the Javanaise Coordinator.

Parameters:
joi : the JVN object id
See also:
JvnObjectImpl.jvnInvalidateWriter()

Implements jvn.JvnRemoteServer.

Definition at line 291 of file JvnServerImpl.java.

References jvn.JvnObject.jvnInvalidateWriter(), and jvn.JvnServerImpl.jvnObjectIds.

00291                                                                                                           {
00292                 JvnObject jo = jvnObjectIds.get(joi);
00293 
00294                 if( jo==null ) {
00295                         throw new JvnException("Object id not found while invalidating reader!");
00296                 } else {
00297                         return jo.jvnInvalidateWriter();
00298                 }
00299         }

Here is the call graph for this function:

Serializable jvn.JvnServerImpl.jvnInvalidateWriterForReader ( int  joi  )  throws java.rmi.RemoteException,jvn.JvnException

Invalidates the write lock held by a Javanaise Object and replaces it with a read lock. This method is normally called by the Javanaise Coordinator.

Parameters:
joi : the JVN object id
See also:
JvnObjectImpl.jvnInvalidateWriterForReader()

Implements jvn.JvnRemoteServer.

Definition at line 310 of file JvnServerImpl.java.

References jvn.JvnObject.jvnInvalidateWriterForReader(), and jvn.JvnServerImpl.jvnObjectIds.

00310                                                                                                                    {
00311                 JvnObject jo = jvnObjectIds.get(joi);
00312 
00313                 if( jo==null ) {
00314                         throw new JvnException("Object id not found while invalidating reader!");
00315                 } else {
00316                         return jo.jvnInvalidateWriterForReader();
00317                 }
00318         }

Here is the call graph for this function:


Member Data Documentation

final long jvn.JvnServerImpl.serialVersionUID = -1834717182805714127L [static, private]

Automatically generated serial version ID

Definition at line 26 of file JvnServerImpl.java.

JvnServerImpl jvn.JvnServerImpl.js = null [static, private]

A Javanaise Server is managed as a singleton

Definition at line 31 of file JvnServerImpl.java.

Referenced by jvn.JvnServerImpl.jvnGetServer().

HashMap<Integer,JvnObject> jvn.JvnServerImpl.jvnObjectIds = null [private]

Maps Object IDs to Javanaise Objects.

Definition at line 36 of file JvnServerImpl.java.

Referenced by jvn.JvnServerImpl.jvnInvalidateReader(), jvn.JvnServerImpl.jvnInvalidateWriter(), jvn.JvnServerImpl.jvnInvalidateWriterForReader(), jvn.JvnServerImpl.jvnLockRead(), jvn.JvnServerImpl.jvnLockWrite(), jvn.JvnServerImpl.jvnLookupObject(), jvn.JvnServerImpl.jvnRegisterObject(), and jvn.JvnServerImpl.JvnServerImpl().

JvnRemoteCoord jvn.JvnServerImpl.jvnCoordinator = null [private]

The Javanaise Coordinator.

Definition at line 41 of file JvnServerImpl.java.

Referenced by jvn.JvnServerImpl.jvnLockRead(), jvn.JvnServerImpl.jvnLockWrite(), jvn.JvnServerImpl.jvnLookupObject(), jvn.JvnServerImpl.jvnRegisterObject(), jvn.JvnServerImpl.JvnServerImpl(), and jvn.JvnServerImpl.jvnTerminate().


The documentation for this class was generated from the following file:
Generated on Wed Jan 2 10:16:03 2008 for Javanaise by  doxygen 1.5.4